init();
function init(){
	var oImg = $('img');
	//拿到元素个数
	var len = oImg.length;
	//平均角度
	var deg = 360 / len;
	for (var i = 0; i < len; i++) {
		//给每一张图片
		$(oImg[i]).css({
			transform : 'rotateY(' + deg * i + 'deg) translateZ(350px)',
			transition:'transform 1s ' + (len - 1 - i) * 0.1 + 's'
		});
	}
	bindEvent();
	
}

function bindEvent(){
	var box = $('.box');
	var body = $('body');
	var html = $('html');
	var lastX,lastY,nowX,nowY;
	var disX = 0;
	var disY = 0;
	var roY = 0,roX = -15;
	var timer;
	body.on('mousedown',function(e){
		lastX = e.clientX;
		lastY = e.clientY;
		body.on('mousemove',function(e){
			
			nowX = e.clientX;
			nowY = e.clientY;
			console.log(nowX + ":::" + nowY);
			disX = nowX - lastX;
			disY = nowY - lastY;
			
			//进行Box旋转
			roY += disX * 0.2;
			roX -= disY * 0.2;
			
			box.css({
				transform : 'rotateY(' + roY + 'deg) rotateX(' + roX + "deg)",
				cursor: 'pointer'
			})
			
			
			lastX = nowX;
			lastY = nowY;
		});
		
		
		html.on('mouseup',function(){
			body.off('mousemove');
			clearInterval(timer);
			timer = setInterval(function(){
				disX *= 0.98;
				disY *= 0.98;
				
				roY += disX * 0.2;
				roX -= disY * 0.2;
				box.css({
					transform : 'rotateY(' + roY + 'deg) rotateX(' + roX + "deg)",
					cursor: 'pointer'
				})
				if(Math.abs(disX) < 0.1 && Math.abs(disY) < 0.1){
					clearInterval(timer);
				}
			},20);
		});
		//取消默认事件
		return false;
		
	})
		
		
}
